package com.sunwayhorizo.health.platform.security.persistent;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.sunwayhorizo.health.platform.util.BeanHelper;

@Entity
@NamedQuery(name="SecurityRole.findAll",query="select sr from SecurityRole sr")
@TableGenerator(name = "SecurityRole_IdGenerator", table = "ET_Id_Generator", pkColumnName = "pkColumn", valueColumnName = "valueColumn", pkColumnValue = "SECURITY_ROLE_ID",allocationSize=1)
@Table(name = "SECURITY_ROLE", schema = "ETS")
public class SecurityRole implements java.io.Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "SecurityRole_IdGenerator")
	@Column(name = "ROLE_ID", unique = true, nullable = false, length = 32)
	private String roleId;
	
	@Column(name = "ROLE_NAME", length = 30)
	private String roleName;
	
	@Column(name = "ROLE_CODE", length = 20)
	private String roleCode;
	
	@Column(name = "CREATOR_NAME", length = 20)
	private String creatorName;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "CREATE_TIME", length = 7)
	private Date createTime;
	
	@Column(name = "MODIFIER_NAME", length = 20)
	private String modifierName;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "MODIFY_TIME", length = 7)
	private Date modifyTime;
	
	@Column(name = "REMARK", length = 200)
	private String remark;
	
	@ManyToOne
	@JoinColumn(name = "FATHER_ID")
	private SecurityRole fatherRole;
	
	@OneToMany(mappedBy = "fatherRole",fetch = FetchType.LAZY)
	private List<SecurityRole> dbChildren = new ArrayList<SecurityRole>(0);
	
	@Transient
	private List<SecurityRole> children;
	
	@OneToMany(mappedBy = "role",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
	private List<SecurityPermissionRole> permissionRoles = new ArrayList<SecurityPermissionRole>(
			0);
	
	@OneToMany(mappedBy = "role",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
	private List<SecurityAccountRolePermission> accRolePermissions = new ArrayList<SecurityAccountRolePermission>(
			0);
	
	@OneToMany(mappedBy = "role",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
	private List<SecurityAccountRole> accountRoles = new ArrayList<SecurityAccountRole>(
			0);

	public SecurityRole() {
	}

	public SecurityRole(String roleId) {
		this.roleId = roleId;
	}

	public SecurityRole(String roleId, String roleName, String roleCode,
			String creatorName, Date createTime, String modifierName,
			Date modifyTime, String remark, SecurityRole fatherRole,
			List<SecurityRole> dbChildren, List<SecurityPermissionRole> permissionRoles,
			List<SecurityAccountRolePermission> accRolePermissions,
			List<SecurityAccountRole> accountRoles) {
		super();
		this.roleId = roleId;
		this.roleName = roleName;
		this.roleCode = roleCode;
		this.creatorName = creatorName;
		this.createTime = createTime;
		this.modifierName = modifierName;
		this.modifyTime = modifyTime;
		this.remark = remark;
		this.fatherRole = fatherRole;
		this.dbChildren = dbChildren;
		this.permissionRoles = permissionRoles;
		this.accRolePermissions = accRolePermissions;
		this.accountRoles = accountRoles;
	}

	public String getRoleId() {
		return this.roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRoleCode() {
		return this.roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	public String getCreatorName() {
		return this.creatorName;
	}

	public void setCreatorName(String creatorName) {
		this.creatorName = creatorName;
	}
	
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getModifierName() {
		return this.modifierName;
	}

	public void setModifierName(String modifierName) {
		this.modifierName = modifierName;
	}

	
	public Date getModifyTime() {
		return this.modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}
	
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public SecurityRole getFatherRole() {
		return fatherRole;
	}

	public void setFatherRole(SecurityRole fatherRole) {
		this.fatherRole = fatherRole;
	}
	
	public List<SecurityRole> getChildren() {
		return children;
	}

	public void setChildren(List<SecurityRole> children) {
		this.children = children;
	}

	public List<SecurityPermissionRole> getPermissionRoles()
    {
        return permissionRoles;
    }

    public void setPermissionRoles(List<SecurityPermissionRole> permissionRoles)
    {
        this.permissionRoles = permissionRoles;
    }

    public List<SecurityAccountRolePermission> getAccRolePermissions()
    {
        return accRolePermissions;
    }

    public void setAccRolePermissions(List<SecurityAccountRolePermission> accRolePermissions)
    {
        this.accRolePermissions = accRolePermissions;
    }

    public List<SecurityAccountRole> getAccountRoles()
    {
        return accountRoles;
    }

    public void setAccountRoles(List<SecurityAccountRole> accountRoles)
    {
        this.accountRoles = accountRoles;
    }

    public List<SecurityRole> getDbChildren() {
		return dbChildren;
	}

	public void setDbChildren(List<SecurityRole> dbChildren) {
		this.dbChildren = dbChildren;
	}
	
	public void addChild(SecurityRole r){
		if( this.getChildren() == null ){
			this.setChildren(new ArrayList<SecurityRole>());
		}
		this.getChildren().add(r);
	}
	
	@Override
	public String toString() {
		return BeanHelper.toString(this);
	}
}
